import { Component, OnInit, Input, Injector } from '@angular/core';
import { Location } from "@angular/common";
import { HttpClient } from '@angular/common/http';
import { HttpService } from "../service/http.service";
import { Router, ActivatedRoute } from "@angular/router";
import {
  AndOr, Compare, ExpressionPair, PagedResultDto, PagerSearchInput, ElementViewType, BaseComponentConfig,
  SystemFormControl, FieldType, CustomNavigation, ElementShowType, CnBooleanPipe, KeyValueOutput,
  SonPagerSearchInput, LoadRemoteDataType, SortExpression, SortType
} from "../..";
import { NzMessageService, NzModalService, UploadFile } from 'ng-zorro-antd';
import {
  FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators,
  FormControl,
  ValidatorFn,
  AbstractControl
} from "@angular/forms";
import { Observable, Observer, BehaviorSubject } from 'rxjs/';
import { map, filter, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
import { isNumber, isBoolean } from 'util';
import { environment } from "environments/environment";
import { ArSystemFormControl, SearchValue } from "../model/CommonDto";
import { ClassGetter } from '@angular/compiler/src/output/output_ast';

@Component({
  selector: 'app-ng-zorro-page-base-component',
  templateUrl: './ng-zorro-page-base-component.component.html',
  styleUrls: ['./ng-zorro-page-base-component.component.scss']
})
export class NgZorroPageBaseComponent implements OnInit {


  @Input()
  set pKeyFieldValue(value: any) {
    this._pKeyFieldValue = value;
  }

  @Input()
  set caption(value: string) {
    this._caption = value;
  }
  /**
   * 本地存储数据内容.
   */
  storageName = 'Base';
  // 服务等内容
  httpService: HttpService;
  message: NzMessageService;
  fb: FormBuilder;
  nzModalService: NzModalService;
  validateForm: FormGroup;
  route: ActivatedRoute;
  router: Router;
  nghttp: HttpClient;
  location: Location;
  // 组件变量
  _focusEntity: any = this.getNewEntity();
  /**
   * 分页数据属性
   */
  listEntities = new PagedResultDto<any>(0, 0, 1, 10, new Array<any>());
  /**
   * 查询内容
   */
  listSearchValue: Array<ExpressionPair> = new Array<ExpressionPair>();
  // 控件状态等信息
  /**
   * 列表数据加载
   */
  loadingData = false;
  /**
   * 组件初始化
   */
  isSpinning = false;
  /**
   * 操作执行。
   */
  isPending = false;
  /**
   * 表格，全选状态
   */
  allChecked = false;
  /**
   * 选中的第三种状态
   */
  indeterminate = false;
  /**
   * 页面显示状态`列表`，`修改`
   */
  _viewType = ElementViewType.List;
  /**
   * 表单配置信息
   */
  arSystemFormControls: Array<SystemFormControl> = new Array<SystemFormControl>();
  /**
   * 做为子模块时，父节点主键值
   */
  _pKeyFieldValue = 0;
  /**
   * 传入的标题信息
   */
  _caption = '';
  /**
   * 图片预览内容
   */
  preViewImage = {
    showImageModal: false,
    imageModalUrl: ''
  };

  arSortableField = new Array<SortExpression>();
  /**
   * 是否是Navigate访问的。
   */
  isNavigation = false;
  /**
   * 是否显示标题信息
   */
  showTitile = true;
  /**
   * 排序字段
   */
  sortField = {};
  /**
   * 初始化订阅
   */
  IniObserver: Observable<any>;
  /**
     * 上传Excel
     */
  // modal=NzModalService;
  isfirst_uploadExcel = true;
  upExcelfile;
  fileList_uploadExcel: UploadFile[] = [];
  fileList = {};

  get isHaveCheckedField(): boolean {
    return Object.getOwnPropertyNames(this.getNewEntity()).indexOf('IsChecked') !== -1;
  }

  get focusEntity(): any {
    return this.getEntityFromFormGroup(this.validateForm, this._focusEntity);
  }

  set focusEntity(input: any) {
    this.setEntityToFormGroup(this.validateForm, input);
    this._focusEntity = input;
  }

  get viewType(): ElementViewType {
    return this._viewType;

  }

  set viewType(value: ElementViewType) {
    this._viewType = value;
    if (this._viewType === ElementViewType.List) {
      this.getEntityList();
    } else if (this._viewType === ElementViewType.Add) {
      this.focusEntity = this.getNewEntity();
      this.validateForm.markAsPristine();
    }
  }

  get searchVal(): string {
    return this.listSearchValue[0] ? this.listSearchValue[0].propertyValue : '';
  }

  set searchVal(value: string) {
    if (this.listSearchValue) {
      value = value.length > 30 ? value.substring(0, 30) : value;
      this.listSearchValue.forEach(e => {
        e.propertyValue = value;
      });
    }
  }

  get searchCaption(): string {
    return this.arSystemFormControls.filter(e => {
      return e.isSearchField &&
        (e.fieldType === FieldType.Text
          || e.fieldType === FieldType.MultipleText
          || e.fieldType === FieldType.RichText);
    }).map(e => e.fieldCaption).join(",");
  }

  get tableOptons(): Array<CustomNavigation> {
    if (this.componentConfig.Navigation) {
      return this.componentConfig.Navigation.filter(e => e.showType === ElementShowType.TableOperation);
    }
    return new Array<CustomNavigation>();
  }
  get MenuOptons(): Array<CustomNavigation> {
    if (this.componentConfig.Navigation) {
      return this.componentConfig.Navigation.filter(e => e.showType === ElementShowType.MenuBar);
    }
    return new Array<CustomNavigation>();
  }
  // 搜索框内容
  baseSearchChange$ = new BehaviorSubject({ fieldName: '', url: '' });
  // 构造函数
  constructor(protected injector: Injector,
    public componentConfig: BaseComponentConfig,
    protected systemFormControl: ArSystemFormControl = null) {
    // 注入服务组件等
    this.httpService = this.injector.get(HttpService);
    this.message = this.injector.get(NzMessageService);
    this.fb = this.injector.get(FormBuilder);
    this.nzModalService = this.injector.get(NzModalService);
    this.route = this.injector.get(ActivatedRoute);
    this.router = this.injector.get(Router);
    this.nghttp = this.injector.get(HttpClient);
    this.validateForm = this.fb.group({});
    this.location = this.injector.get(Location);

    // 初始化异步数据查询功能。
    this.iniAsyncFindRecord();
    // 数据内容处理
    this.isSpinning = true;
    const componentThis = this;
    const arsystemformControl = systemFormControl ? systemFormControl.SystemFormControls : null;
    this.IniObserver = Observable.create(function (observer: Observer<any>) {
      if (!arsystemformControl && componentConfig.FormName) {
        componentThis.httpService
          .get<Array<SystemFormControl>>(`SystemForm/GetFormControlsByName?name=${componentConfig.FormName}`)
          .then(res => {
            componentThis.setFormAndGetDataList(res, observer);
          });
      } else {
        componentThis.setFormAndGetDataList(arsystemformControl, observer);
      }
    });
  }

  /**
   * 组件初始化,尽量不要写入业务逻辑内容，有可能被子类重写覆盖。
   */
  ngOnInit(): void {
    this.IniObserver.subscribe(e => {
      this.getEntityList();
    });
  }

  /**
   * 初始化异步查询内容
   */
  protected iniAsyncFindRecord() {
    const optionList$: Observable<{ fieldName: string, data: Array<KeyValueOutput> }> =
      this.baseSearchChange$.asObservable().pipe(debounceTime(1000)).pipe(
        switchMap((value: { fieldName: string, url: string }) => {
          if (value.url) {
            return new Promise(async (resolve, reject) => {
              const result = await this.httpService.get<Array<KeyValueOutput>>(value.url);
              resolve({ fieldName: value.fieldName, data: result });
            });
          } else {
            return new Promise(resolve => {
              resolve({ fieldName: value.fieldName, data: new Array<KeyValueOutput>() });
            });
          }
        }));
    optionList$.subscribe(data => {
      const findField = this.arSystemFormControls.filter(e => e.fieldName === data.fieldName)[0];
      if (findField) {
        findField.fieldData = data.data;
      }
    });
  }

  /**
   * 更新选择按钮状态
   */
  protected refreshStatus() {
    const allChecked = this.listEntities.entities.length > 0 && this.listEntities.entities.every(value => value.IsChecked === true);
    const allUnChecked = this.listEntities.entities.every(value => !value.IsChecked);
    this.allChecked = allChecked;
    this.indeterminate = (!allChecked) && (!allUnChecked);
  }

  /**
   * 取消/全选
   * @param value 状态值
   */
  protected checkAll(value) {
    if (value) {
      this.listEntities.entities.forEach(data => {
        data.IsChecked = true;
      });
    } else {
      this.listEntities.entities.forEach(data => {
        data.IsChecked = false;
      });
    }
    this.refreshStatus();
  }

  /**
   * 根据设置信息初始化表单、查询、数据格式化内容、并获取数据。
   * @param systemFormControl 系统设置信息
   */
  protected async setFormAndGetDataList(systemFormControl: Array<SystemFormControl>, observer: Observer<any>) {
    this.arSystemFormControls = systemFormControl == null ? [] : systemFormControl;
    for (const i of Object.keys(this.arSystemFormControls)) {
      const index = parseInt(i, 0);
      const fieldName = this.arSystemFormControls[index].fieldName;
      const entity = this.getNewEntity();
      const formControl = this.arSystemFormControls[index];
      if (formControl.remoteData &&
        (formControl.loadRemoteDataType === null || formControl.loadRemoteDataType === LoadRemoteDataType.LoadAll)) {
        // 数据地址
        let remoteurl = this.arSystemFormControls[index].remoteData;
        // 主键内容替换
        remoteurl = remoteurl.indexOf('{PID}') !== -1
          ? `${remoteurl.replace('{PID}', this._pKeyFieldValue.toString())}`
          : `${this.arSystemFormControls[index].remoteData}`;
        const dataResult = await this.httpService.get<Array<KeyValueOutput>>(remoteurl);
        if (formControl.fieldType === FieldType.Select) {
          dataResult.forEach(e => e.dValue = parseInt(e.dValue, 10));
        } else if (isBoolean(entity[fieldName])) {
          dataResult.forEach(e => e.dValue = Boolean(e.dValue));
        }
        this.arSystemFormControls[index].fieldData = dataResult;
      }
    }
    this.listSearchValue = this.iniSearchValue(this.arSystemFormControls);
    this.validateForm = this.iniFormGroup(this.arSystemFormControls);
    this.arSortableField = this.iniSortField(this.arSystemFormControls);
    this.isSpinning = false;
    observer.next(1);
  }

  /**
   * 根据设置初始化表单信息
   * @param input 系统表单设置
   */
  protected iniFormGroup(input: Array<SystemFormControl>): FormGroup {
    const group = {};
    if (input) {
      input.forEach(e => {
        const arValids = [],
          controlConfig = [];
        controlConfig.push(null);
        if (e.fieldType !== FieldType.Toggle) {
          if (e.isRequired) {
            arValids.push(Validators.required);
          }
          if (e.minLength) {
            arValids.push(Validators.minLength(e.minLength));
          }
          if (e.maxLength) {
            arValids.push(Validators.maxLength(e.maxLength));
          }
        }
        // if (e.remoteValid) {
        //   controlConfig.push({
        //     validators: arValids,
        //     updateOn: 'blur',
        //     // asyncValidators: [this.remoteAsyncValidator(e.fieldName, e.remoteValid)]
        //   });
        // } else {
        //   controlConfig.push(arValids);
        // }
        controlConfig.push(arValids);
        group[e.fieldName] = controlConfig;
      });
    }
    const formGroup = this.fb.group(group);
    return formGroup;
  }

  /**
   * 根据表单设置初始化查询内容
   * @param input 系统表单设置
   */
  protected iniSearchValue(input: Array<SystemFormControl>): Array<ExpressionPair> {
    const reslut = new Array<ExpressionPair>();
    input.filter(e => {
      return e.isSearchField &&
        (e.fieldType === FieldType.Text || e.fieldType === FieldType.MultipleText || e.fieldType === FieldType.RichText);
    }).forEach(e => {
      reslut.push(new ExpressionPair(e.fieldName, "", Compare.Contains, AndOr.Or));
    });
    return reslut;
  }

  /**
 * 根据表单设置初始化排序内容
 * @param input 系统表单设置
 */
  protected iniSortField(input: Array<SystemFormControl>): Array<SortExpression> {
    const reslut = new Array<SortExpression>();
    input.filter(e => {
      return e.canSortable;
    }).forEach(e => {
      reslut.push(new SortExpression(e.fieldName, SortType.Null));
    });
    return reslut;
  }

  /**
   * 数据远程异步验证
   * @param fieldName 字段名称
   * @param remoteUrl 验证地址
   */
  // remoteAsyncValidator(fieldName: string, remoteUrl: string): ValidatorFn {
  //   return async (control: AbstractControl): Promise<{ [key: string]: any }> => {
  //     if (control.value && control.value.length > 0) {
  //       const validBody = this.getRemoteValidBody(control.value, fieldName);
  //       const result = await this.httpService.post<boolean>(remoteUrl, validBody);
  //       if (result) {
  //         const body = {};
  //         body[fieldName] = { value: control.value };
  //         return body;
  //       }
  //     }
  //     return null;
  //   };
  // }


  /**
   * 重置页面验证
   *
   * @protected
   * @param {MouseEvent} $event
   * @memberof NgZorroPageBaseComponent
   */
  protected resetForm($event: MouseEvent) {
    $event.preventDefault();
    this.validateForm.reset();
    if (this.validateForm.controls) {
      for (const key of Object.keys(this.validateForm.controls)) {
        this.validateForm.controls[key].markAsPristine();
      }
    }
    this.setEntityToFormGroup(this.validateForm, this._focusEntity);
  }

  /**
   * 从formgroup中获取值到传输模型
   *
   * @protected
   * @param {FormGroup} fb
   * @param {T} entity
   * @returns {T}
   * @memberof NgZorroPageBaseComponent
   */
  protected getEntityFromFormGroup(fb: FormGroup, entity: any): any {
    for (const key of Object.keys(fb.controls)) {
      entity[key] = fb.controls[key].value;
    }
    return entity;
  }

  /**
   * 模型值复制到formgroup
   *
   * @protected
   * @param {FormGroup} fb
   * @param {T} entity
   * @returns {*}
   * @memberof NgZorroPageBaseComponent
   */
  protected setEntityToFormGroup(fb: FormGroup, entity: any): FormGroup {
    for (const key of Object.keys(entity)) {
      if (fb.controls[key]) {
        fb.controls[key].setValue(entity[key]);
      }
    }
    return fb;
  }

  /**
   * 添加内容
   */
  async addEntity() {
    for (const i of Object.keys(this.validateForm.controls)) {
      this.validateForm.controls[i].markAsDirty();
      this.validateForm.controls[i].updateValueAndValidity();
    }
    if (!this.validateForm.valid) {
      return;
    }
    this.isPending = true;
    try {
      const hasKeyentity = { ...this.focusEntity };
      if (this.componentConfig.PKeyFieldName && this._pKeyFieldValue) {
        hasKeyentity[this.componentConfig.PKeyFieldName] = this._pKeyFieldValue;
      }
      if (this.focusEntity[this.componentConfig.KeyFieldName]) {
        await this.httpService.post<any>(this.componentConfig.UpdateUrl, hasKeyentity);
      } else {
        await this.httpService.post<any>(this.componentConfig.CreateUrl, hasKeyentity);
      }
    } finally {
      this.isPending = false;
    }
    this.fileList = {};
    this.listEntities.currentPageIndex = 1;
    this.viewType = ElementViewType.List;
  }

  /**
   * 获取列表默认分页
   */
  async getEntityList() {
    try {
      this.loadingData = true;
      await this.getEntityListAsync(true);
    } finally {
      this.refreshStatus();
      this.loadingData = false;
    }
  }

  /**
   * 搜索条传入的过滤条件，触发的查询。
   * @param where 自定义过滤条件
   */
  async searchBar(where) {
    this.listSearchValue = where;
    await this.getEntityListAsync(true);
  }

  /**
   * 获取数据，没有基本状态监视内容更改的。
   */
  async getEntityListAsync(input: any) {
    if (input === true || (input > 0 && input !== this.listEntities.currentPageIndex)) {
      let searchBody: any;
      if (this.componentConfig.PKeyFieldName && this._pKeyFieldValue) {
        searchBody = new SonPagerSearchInput(
          this._pKeyFieldValue,
          this.listEntities.currentPageIndex,
          this.listEntities.pageSize,
          this.listSearchValue,
          this.arSortableField);
      } else {
        searchBody = new PagerSearchInput(
          this.listEntities.currentPageIndex,
          this.listEntities.pageSize,
          this.listSearchValue,
          this.arSortableField);
      }
      // console.log(this.listSearchValue);
      if (window.localStorage.getItem(this.storageName)) {
        this.listEntities = JSON.parse(window.localStorage.getItem(this.storageName));
        window.localStorage.removeItem(this.storageName);
      } else {
        this.listEntities = await this.httpService.post<PagedResultDto<any>>(this.componentConfig.GetListUrl, searchBody);
      }
    }
  }

  /**
   * 删除单个内容
   * @param id 主键
   */
  async deleteEntity(id: number) {
    const msgId = this.message.loading('正在执行删除中', { nzDuration: 0 }).messageId;
    try {
      let body: any;
      if (this.componentConfig.PKeyFieldName && this._pKeyFieldValue) {
        body = {
          "id": this._pKeyFieldValue,
          "ids": [id]
        };
      } else {
        body = [id];
      }
      await this.httpService.post(this.componentConfig.DeleteUrl, body);
      await this.getEntityList();
    } finally {
      this.message.remove(msgId);
    }

  }
  /**
   * 删除选中内容
   */
  async deleteChecked() {
    const thisInstance = this;
    const itemKey = [];
    this.listEntities.entities.filter(e => e.IsChecked).forEach(e => {
      itemKey.push(e[this.componentConfig.KeyFieldName]);
    });
    let body: any;
    if (this.componentConfig.PKeyFieldName && this._pKeyFieldValue) {
      body = {
        "id": this._pKeyFieldValue,
        "ids": itemKey
      };
    } else {
      body = itemKey;
    }
    this.nzModalService.confirm({
      nzTitle: '您是否确认要删除这项内容',
      nzContent: `已经选中的：${itemKey.length}项内容？`,
      nzZIndex: 1010,
      nzOnOk() {
        return new Promise(async (resolve, reject) => {
          try {
            await thisInstance.httpService.post(thisInstance.componentConfig.DeleteUrl, body);
            await thisInstance.getEntityList();
            thisInstance.refreshStatus();
            resolve();
          } catch (error) {
            reject();
          }
        }).catch(e => {
        });
      }
    });
  }

  /**
   * 修改内容
   * @param id 主键
   */
  async editEntity(id: number) {
    const msgId = this.message.loading('正在获取数据', { nzDuration: 0 }).messageId;
    try {
      let url = '';
      if (this.componentConfig.PKeyFieldName && this._pKeyFieldValue) {
        url = `${this.componentConfig.GetSingle}?pid=${this._pKeyFieldValue}&id=${id}`;
      } else {
        url = `${this.componentConfig.GetSingle}?input=${id}`;
      }
      const findEntity = await this.httpService.get<any>(url);
      this.focusEntity = findEntity;
      this.viewType = ElementViewType.Edit;
      this.validateForm.markAsPristine();
    } finally {
      this.message.remove(msgId);
    }
  }

  async searchChange(searchText: string, fieldName: string) {
    if (searchText) {
      const findField = this.arSystemFormControls.filter(e => e.fieldName === fieldName)[0];
      if (findField) {
        // findField.fieldData = await this.httpService.get<Array<KeyValueOutput>>(`${findField.remoteData}${searchText}`);
        this.baseSearchChange$.next({ fieldName: fieldName, url: `${findField.remoteData}${searchText}` });
      }
    }
  }
  /**
   * 图片大小限制检查
   */
  beforeImgUpload = (file: File) => {
    const isJPG = (
      file.type === 'image/jpeg' ||
      file.type === 'image/png' ||
      file.type === 'image/gif' ||
      file.type === 'image/bmp'
    );
    if (!isJPG) {
      this.message.error('只能上传jpg文件!');
    }
    const isLt2M = file.size / 1024 / 1024 < 2;
    if (!isLt2M) {
      this.message.error('图片大小超过2MB!');
    }
    return isJPG && isLt2M;
  }
  beforeUpload = (file: UploadFile): boolean => {
    const isLt2M = file.size / 1024 / 1024 < 200;
    if (!isLt2M) {
      this.message.error('文件大小超过2MB!');
    }
    return isLt2M;
  }

  // bindingFormFile = (value) => {
  //   // this.fileList[value.name] = value.file;
  //   return Observable.create(function (observer: Observer<any>) { }).subscribe();
  //   // return new Observable().subscribe();
  // }

  handleChange(info: any, fieldName: string) {
    const fileList = info.fileList.length > 0 ? [info.fileList[0]] : []; // info.fileList[0];
    this.fileList[fieldName] = fileList.filter(item => {
      item.status = 'done';
      return true;
    });
    this.focusEntity[fieldName] = this.fileList[fieldName].length > 0 ? '1' : '';
    this.validateForm.controls[fieldName].setValue(this.fileList[fieldName].length > 0 ? '1' : '');
    return Observable.create(function (observer: Observer<any>) { }).subscribe();
  }
  /**
   * 用于附件绑定选择文件后的处理函数
   */
  bindingForm = (value) => {
    this.getBase64(value.file, (img: any) => {
      this.focusEntity[value.name] = img;
      this.validateForm.controls[value.name].setValue(img);
    });
    return Observable.create(function (observer: Observer<any>) { }).subscribe();
  }
  /**
   * 获取文件多base64码
   * @param img 文件
   * @param callback 回调函数
   */
  public getBase64(file: File, callback: (file: any) => void) {
    const reader = new FileReader();
    reader.addEventListener('load', () => callback(reader.result));
    reader.readAsDataURL(file);
  }


  bindingFormFile = (value) => {
    // this.fileList[value.name] = value.file;
    this.getBase64(value.file, (img: any) => {
      this.focusEntity[value.name] = img;
      this.validateForm.controls[value.name].setValue(img);
    });
    return Observable.create(function (observer: Observer<any>) { }).subscribe();
  }

  // handleChange(info: any, fieldName: string): void {
  //   const fileList = info.fileList.length > 0 ? [info.fileList[0]] : []; // info.fileList[0];
  //   this.fileList[fieldName] = fileList.filter(item => {
  //     item.status = 'done';
  //     return true;
  //   });
  //   this.focusEntity[fieldName] = this.fileList[fieldName].length > 0 ? '1' : '';
  //   this.validateForm.controls[fieldName].setValue(this.fileList[fieldName].length > 0 ? '1' : '');
  // }

  /**
   * 显示图片预览
   * @param url 图片地址
   */
  showImageView(url: string) {
    this.preViewImage.imageModalUrl = url;
    this.preViewImage.showImageModal = true;
  }

  /**
   * 远程验证信息获取，主要针对GET和post请求内容生成，派生类根据需求重写该函数。
   * @param value 验证值
   */
  getRemoteValidBody(value: any, fieldName: string): any {
    const keyName = this.componentConfig.KeyFieldName;
    const KeyValue = this.focusEntity[this.componentConfig.KeyFieldName];
    if (this.focusEntity && keyName && KeyValue) {
      return new Array<ExpressionPair>(
        new ExpressionPair(fieldName, value, Compare.Equal, AndOr.And),
        new ExpressionPair(keyName, KeyValue, Compare.NotEqual, AndOr.And),
      );
    } else {
      return new Array<ExpressionPair>(
        new ExpressionPair(fieldName, value, Compare.Equal, AndOr.And),
      );
    }
  }
  /**
   * 字段排序
   * @param sortName 排序字段
   * @param value 排序类型`升序和降序`
   */
  sort(sortName, value) {
    const findSorts = this.arSortableField.filter(e => e.PropertyName === sortName);
    if (findSorts.length > 0) {
      const sort = findSorts[0];
      sort.sortType = value ? (value === 'ascend' ? SortType.Asc : SortType.Desc) : SortType.Null;
    }
    this.sortField[sortName] = value;
    this.getEntityList();
  }

  /**
   * 判断是否BASE64还是URL
   * @param fieldName 字段值
   */
  protected isHaveImage(fieldName: string): boolean {
    return (<string>this.focusEntity[fieldName]).indexOf('/userfiles/') !== -1;
  }

  dataListFilter(event: Event) {
    this.getEntityList();
  }

  /**
   * 退回、返回
   */
  goBack() {
    this.location.back();
  }

  /**
   * 子窗体显示
   * @param entity 实体
   * @param tag 标识
   */
  showModalForComponent(entity: any, tag: any) { }

  /**
   * 获取空的实例
   */
  getNewEntity(): any { }

  /**
   *  路由页面跳转
   * @param url 路由地址
   * @param pid 父ID
   */
  navigateCustom(url: string, pid: any) { }
  MenuAction(url: string, tag: string) { }

  /** 
   * 上传Excel按钮change事件
  */
  handleChange_uploadExcel(pid) {

  }
  /** 
    * 上传Excel按钮点击事件
   */
  beforeUpload_uploadExcel = (file: UploadFile): boolean => {
    // if(!this.isfirst_uploadExcel){
    this.fileList_uploadExcel.push(file);
    this.nzModalService.confirm({
      nzTitle: '<i>是否确定上传学生Excel?</i>',
      nzContent: '<b>点击确定上传</b>',
      nzOnOk: () => {
        this.handleChange_uploadExcel(this._pKeyFieldValue.toString());
      }
    });
    //  }
    //  this.isfirst_uploadExcel=false;
    return false;
  }

  e_prevent_default = (e: MouseEvent): void => {
    e.preventDefault();
  }
}
